<?php
 if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 class MY_Controller extends Controller{
     var $CI;
     var $data;
     var $controller_name;
     
     function MY_Controller(){
         parent::Controller();
         $this->CI =& get_instance();
         $this->CI->load->model($this->CI->config->item('folder_db').'M_common','common',TRUE);
         if($this->session->userdata('username') == ""){
             $this->session->set_flashdata("message",6);
             redirect('login');
         }
     }
     
     function get_list_menu(){
         $this->load->model('m_menu');
         $data = $this->m_menu->getModule();
         
         $this->load->model('m_user');
         $privilege = $this->m_user->getPrivilege($this->session->userdata('id'));
         foreach ($privilege as $hak);
         $akses_mod = explode('-', $hak['hak_module']);
         $akses_sub = explode('-', $hak['hak_sub']);
         
         $no = 1;
         $content = "";
         
         foreach ($data as $key => $row){
             $mod_user = in_array($row['module']->id, $akses_mod);
             if($mod_user){
                 $content .= "<ul class='sf-menu'>";
                 if($row['module']->url <> '#'){
                     $content .= "<li id='mod_".$no++."'>".anchor($row['module']->url, $row['module']->nama)."</li>";
                 }else if($row['module']->url == '#'){
                     $content .= "<li id='mod_".$no++."'><a href='".$row['module']->url."' id='menu_".$no++."'>".$row['module']->nama."</a>";
                     //".anchor($row['module']->url,$row['module']->nama, "id='menu_".$no++."'")."
                     if(count($row['subModule']) > 0){
                         $content .= "<ul>";
                             foreach ($row['subModule'] as $sub){
                                 $sub_user = in_array($sub->id, $akses_sub);
                                 if($sub_user){
                                   $content .= "<li>";  
                                   $content .= anchor($sub->url, $sub->nama, "");
                                   $content .= "</li>";
                                 }
                             }
                         $content .= "</ul>";
                     }
                 }
                 $content .= "</ul>";
             }
         }
        
        return $content;
     }
     function getUserLogin(){
         $idUser = $this->session->userdata('id');
         $idMember = $this->session->userdata('id_member');
         
         $this->load->model('m_user');
         $this->load->model('m_member');
         $data['user'] = $this->m_user->getUserById($idUser);
         $data['keanggotaan'] = $this->m_member->getKeanggotaanById($idMember);
         
         return $data;
     }
     function getSaldo(){
         $this->load->model('m_rekap_keuangan_bulanan');
         
         $data['saldo'] = $this->m_rekap_keuangan_bulanan->getAllSaldo();
         return $data;
     }
     public function render($dataContent=''){
         $this->controller_name = $this->CI->router->fetch_directory().$this->CI->router->fetch_class();
	 $this->data = $dataContent;
         $this->data['path'] = $this->controller_name;
         $this->data['menu'] = $this->get_list_menu();
         $this->data['user'] = $this->getUserLogin();
         $this->data['allSaldo'] = $this->getSaldo();
         $this->CI->load->view("template/template2", $this->data);
     }
 }
?>
